<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'north',border:false" style=" height:45px;padding:5px;border-bottom:1px solid #95B8E7;">
        <div style="float:left; padding:4px 0 0;">
            <a href="#" class="easyui-linkbutton notifyaddsub" data-options="iconCls:'icon-ok'" onclick="addnotify()"><?php echo (@$status == 1)?'修改':'发布';?></a>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:notifyclose();">取消</a>
        </div>        
    </div>
    <div data-options="region:'center',border:false" style=" padding-bottom:10px;;-moz-user-select:text; -webkit-user-select:text; -ms-user-select:text; -khtml-user-select:text; user-select:text;">
    	<div style="padding:6px;">          	         
            <div style="padding-left: 64px;margin:5px;font-size: 12px; font-family:'Microsoft Yahei';border-bottom:1px solid #95B8E7; min-height:32px;">
            	<label id="selectuser_tooltip_notify_add_sj" class="easyui-linkbutton" style=" margin-left:-62px;float:left;" onclick="javascript:selectuser_fun('发布范围','notify_add_sj')">选择范围：</label>
                <div style="padding: 0 0 6px;">
                	<input id="notify_add_sj_select_id" type="hidden" value="<?php echo (!empty($arr[0]->to_id))?$arr[0]->to_id:'';?>">
                    <textarea id="notify_add_sj_select_user" style="width:98%;font-family:'Microsoft Yahei'; border:0;overflow:auto;" readonly="readonly"><?php echo (!empty($arr[0]->to_name))?$arr[0]->to_name:'';?></textarea>
				</div>  
            </div>           
            <div style="padding-left: 68px;margin:5px;font-size: 12px; font-family:'Microsoft Yahei';border-bottom:1px solid #95B8E7; height:32px; cursor:clear: both;">
            	<label style=" margin-top:4px;margin-left:-60px;float:left;color: #999;">主　题：</label>
                <div style="padding: 2px 0 0;">
                	<input id="notifytitle" class="panel-body" type="text" style="width:100%; height:22px;font-size: 14px;
font-weight: 700;border: 0;outline: 0;font-family:'Microsoft Yahei';" value="<?php echo (!empty($arr[0]->to_id))?$arr[0]->title:'';?>">
				</div>            	
            </div>
            <div style="padding-left: 68px;margin:5px;font-size: 12px; font-family:'Microsoft Yahei';border-bottom:1px solid #95B8E7; height:32px; cursor:clear: both;">
            	<label style=" margin-top:4px;margin-left:-60px;float:left;color: #999;">
                	类　型：
                    <select id="notify_type" style="width:100px"></select>
                    <div id="notify_type_sp">
                        <div style="color:#99BBE8;background:#fafafa;padding:5px;">选择通知或公告</div>
                        <div style="padding:10px">
                            <input type="radio" name="lang" value="1"><span>通知</span><br/>
                            <input type="radio" name="lang" value="2"><span>公告</span><br/>
                        </div>
                    </div>
                    <script type="text/javascript">
						$(function(){
							$('#notify_type').combo({
								required:true,
								editable:false,
								panelHeight:'auto',
								missingMessage:"请选择发布类型"
							});
							$('#notify_type_sp').appendTo($('#notify_type').combo('panel'));
							$('#notify_type_sp input').click(function(){
								var v = $(this).val();
								var s = $(this).next('span').text();
								$('#notify_type').combo('setValue', v).combo('setText', s).combo('hidePanel');
							});
						});
					</script>
                	&nbsp;&nbsp;&nbsp;&nbsp;
                	开始时间: 
             		<input id="notyif_manage_ids" class="easyui-datebox" editable="false" data-options="sharedCalendar:'#notyif_manage_id'" value="<?php echo (!empty($arr[0]->begin_date))?$arr[0]->begin_date:date("Y-m-d",time());?>">&nbsp;&nbsp;&nbsp;&nbsp;
    				结束时间: <input id="notyif_manage_ide" class="easyui-datebox" editable="false" data-options="sharedCalendar:'#notyif_manage_id'" value="<?php echo (!empty($arr[0]->end_date))?$arr[0]->end_date:'';?>">&nbsp;&nbsp;&nbsp;&nbsp;
                </label>
                <div id="notyif_manage_id" class="easyui-calendar"></div>
    		</div>
            <div style="margin:5px;font-size: 12px; font-family:'Microsoft Yahei'; position:relative">
                <div style="float:left; position:absolute; margin-left:90px;"> <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-folder'" onclick="dialog_public('文件柜','file_cabinets/select_filebox_out/notify')">个人文件柜</a></div>
				<input id="notify_file_upload" name="notify_file_upload" type="file" multiple>
                <script type="text/javascript">
				var fileList_notify = new Array();
				var is_upload_all_notify=false;
					<?php $timestamp = time();?>
					$(function() {
						$('#notify_file_upload').uploadify({
							'height'          : 24,
							'width'           : 80,
							'buttonText'      : '上传附件',
							'removeCompleted' : false,
							'fileTypeDesc'    : '所有文件',
        					//'fileTypeExts'    : '*.*',
							//'fileTypeExts'	  : '<?php echo $this->attachment_type_str;?>',
							'fileSizeLimit'   : '<?php echo $this->attachment_size;?>',
							'swf'             : '<?php echo base_url().'data/uploadify/uploadify.swf'?>',
							'uploader'        : '<?php echo base_url().'attachment/upload'?>',
							'formData' : {
								'attdir'    :'notify',
								'timestamp' : '<?php echo $timestamp;?>',
								'token'     : '<?php echo md5('unique_salt' . $timestamp);?>'
							},
							'onSelect' : function(file){//当每个文件添加至队列后触发 
								is_upload_all_notify = true;
							
							},
							'onUploadSuccess' : function(file, data, response) {
								//alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
								//file.name = data+'.'+file.name;
								var obj = eval('(' + data + ')'); 
								if(obj.flag){									
									file.daterand = obj.str;
									file.name = obj.file_name;
									fileList_notify.push(file);
								}else{
									alert(obj.str);
								}
								//file.daterand = data;
								//fileList_notify.push(file);
							},
							'onQueueComplete' : function(queueData) {
								//alert(queueData.uploadsSuccessful + ' files were successfully uploaded.');
								//allPrpos(queueData.files);
								is_upload_all_notify = false;
								//单击上传文件的取消按钮时，判断该文件是否已经上传过，如果已经上传过，需要做清理工作
								$("#notify_file_upload-queue .cancel").on("click", function() {//JQUERY 2.0版本用on，1.9以前用live
									//取得本次取消的上传文件ID号		
									var fileId = $(this).parents(".uploadify-queue-item").attr("id");
									var fileInfo = null;
									//fileList_notify中保存了所有的已上传文件信息。
									for (var i=0; i<fileList_notify.length; i++) {
										if(fileList_notify[i].id == fileId) {
											fileInfo = fileList_notify[i];
											fileList_notify.splice(i, 1);
											break;
										}
									}
									
									//如果文件已经上传（即fileInfo不为空）
									if (fileInfo != null) {
										//将已经上传的文件从上传文件队列中清除（不然取消该已上传的文件后，再选择相同的文件上传将会提示“文件已存在！”
										delete queueData.files[fileId];
										
										//将垃圾文件从后台服务器中清除
										//var suggest = {};
										//suggest.fileList_notify = [fileInfo]; 
										
										$.post("<?php echo base_url().'attachment/upload_del'?>",{
											data:JSON.stringify(fileInfo),
											m:'notify'
										},function(data,status){
											if(!data.status){
												$.messager.alert('提示','服务器端未能删除该文件','info');
												//alert('服务器端未能删除该文件');
											}
										},'JSON');
														
									}									
								});
							},
							'onCancel' : function(file) {
								$.messager.alert('提示','文件 ' + file.name + ' 被取消。','info');
								//alert('文件 ' + file.name + ' 被取消.');
							},
							'onSelectError': function (file, errorCode, errorMsg) {  
								switch (errorCode) {  
									case -100:  
										$.messager.alert('提示','上传的文件数量已经超出系统限制的' + $('#notify_file_upload').uploadify('settings', 'queueSizeLimit') + '个文件！','info');
										//alert("上传的文件数量已经超出系统限制的" + $('#file_upload').uploadify('settings', 'queueSizeLimit') + "个文件！");  
										break;  
									case -110:  
										$.messager.alert('提示','文件 [' + file.name + '] 大小超出系统限制的' + $('#notify_file_upload').uploadify('settings', 'fileSizeLimit') + ' 大小！','info');
										//alert("文件 [" + file.name + "] 大小超出系统限制的" + $('#file_upload').uploadify('settings', 'fileSizeLimit') + "大小！");  
										break;  
									case -120:  
										$.messager.alert('提示','文件 [' + file.name + '] 大小异常！','info');
										//alert("文件 [" + file.name + "] 大小异常！");  
										break;  
									case -130:  
										$.messager.alert('提示','文件 [' + file.name + '] 类型不正确！','info');
										//alert("文件 [" + file.name + "] 类型不正确！");  
										break;  
								}  
								return false;  
							},
							'onFallback': function () {  
								$.messager.alert('提示','您未安装FLASH控件，无法上传！请安装FLASH控件后再试。','info');
								//alert("您未安装FLASH控件，无法上传！请安装FLASH控件后再试。");  
							}
						});
					});
					
				</script>
					
            </div>
        </div>
        <div style="padding:0 12px 12px; clear:both">
            <script type="text/plain" id="notify_editor">
			<?php echo (!empty($arr[0]->content))?$arr[0]->content:'';?>
            </script>  
            <script type="text/javascript">
                UE.getEditor('notify_editor',{
                    //这里可以选择自己需要的工具按钮名称,此处仅选择如下五个
                    toolbars:[['source', '|', 'undo', 'redo', '|',
                    'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'removeformat', 'formatmatch', 'autotypeset', 'pasteplain', '|', 'forecolor', 'backcolor', '|',
                    'paragraph', 'fontfamily', 'fontsize', '|',
                    'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|',
                    'link', 'unlink', '|',
                    'emotion', 'scrawl', 'map', '|',
                    'horizontal', 'date', 'time', 'spechars', 'snapscreen', '|',
                    'inserttable']],
                    autoClearinitialContent:false,//focus时自动清空初始化时的内容
                    wordCount:false,//关闭字数统计
                    elementPathEnabled:false,//关闭elementPath
                    initialFrameHeight:200,//默认的编辑区域高度
					initialFrameWidth:"100%"
                });
            </script>
        </div>
        <div id="notify_new_more_options_box" style="display:none; padding:0 12px 12px;">
        	<input id="notify_add_top_check" type="checkbox" name="qx" value="1" /><label for="notify_add_top_check">置顶</label>
            <input id="notify_add_alert_check" type="checkbox" name="qx" value="1" checked="checked"/><label for="notify_add_alert_check">内部短信提醒</label>
        </div>
        <div style="padding:0 12px 12px;">
            <div style="float:left;">
                <a href="#" class="easyui-linkbutton notifyaddsub" data-options="iconCls:'icon-ok'" onclick="addnotify()"><?php echo ($status == 1)?'修改':'发布';?></a>
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:notifyclose();">取消</a>
            </div>
            <div style="float:right;">
                <a href="#" class="easyui-linkbutton" data-options="plain:true" >发布人：<?php echo $this->session->userdata('user_name');?></a>
                <a id="notify_new_more_options_id" href="#" class="easyui-linkbutton" data-options="plain:true,iconAlign:'right',iconCls:'accordion-collapse'"><span id="notify_new_more_options_text">更多选项</span></a>
            </div>
        </div>
    </div>
</div>

<style>
	#edui1{width:100% !important}/* 这个ID为编辑器的ID */
	#edui1_iframeholder{width:100% !important}/* 这个ID为编辑器可编辑区域的ID */
</style>
<script>
$(document).ready(function(){
	$("#notify_new_more_options_id").click(function(){
		var v = $("#notify_new_more_options_box").css("display");
		if(v == 'none'){
			$("#notify_new_more_options_box").show();
			$('#notify_new_more_options_id').linkbutton({iconCls:'accordion-expand'});
			$("#notify_new_more_options_text").empty().append('隐藏选项');
		}else{
			$("#notify_new_more_options_box").hide();
			$('#notify_new_more_options_id').linkbutton({iconCls:'accordion-collapse'});
			$("#notify_new_more_options_text").empty().append('更多选项');
		}
	});
	var v = '<?php echo (!empty($arr[0]->type_id))?$arr[0]->type_id:'';?>';
	if(v != ''){
		var s = (v == 1)?'通知':'公告';
		$('#notify_type').combo('setValue', v).combo('setText', s);
	}
	
	selectuser_tooltip('选择发送范围','notify_add_sj');//tooltip提示
});

$('#notyif_manage_ids').datebox({
	onSelect: function (date) {
		var now = new Date();
        var d1 = new Date(now.getFullYear(), now.getMonth(), now.getDate());
		if(date<d1){
			var str = now.getFullYear()+"-"+(now.getMonth() + 1)+"-"+now.getDate();
			$('#notyif_manage_ids').datebox('setValue', str);	// set datebox value
			$.messager.alert('警告','开始日期不能小于当前日期','warning');
		}
	}
});
$('#notyif_manage_ide').datebox({
	onSelect: function (date) {
		var now = new Date();
        var d1 = new Date(now.getFullYear(), now.getMonth(), now.getDate());
		if(date<d1){
			$('#notyif_manage_ide').datebox('setValue', '');	// set datebox value
			$.messager.alert('警告','结束日期不小于当前日期','warning');
		}
		var eids = $("#notyif_manage_ids").datebox('getValue');
		var newDt=new Date(eids.replace("-","/")); 
		if(eids != '' && date<newDt){
			$('#notyif_manage_ide').datebox('setValue', '');	// set datebox value
			$.messager.alert('警告','结束日期不能小于开始日期','warning');
		}
	}
});

//从文件柜选取文件函数
/*
function notify_select_filebox(){
	$('#dialog_custom_box').dialog({
		title: '文件柜',
		width: 600,
		height: 500,
		closed: false,
		cache: false,
		href: '<?php echo base_url('file_cabinets/select_filebox_out')?>/notify',
		modal: true,
		onClose:function(){
			
		}
	});
}
*/
function addnotify(){//进行相应检查后发送通知公告
	if($("#notify_add_sj_select_user").val() == ''){//如果收件人为空，则直接弹出选择收件人对话框，不提示
		selectuser_fun('发布范围','notify_add_sj');
		return false;
	}else if(is_upload_all_notify === true){//如果有附件正在上传中，则取消提交并返回
		$.messager.alert('提示','附件正在上传中，请稍后提交！','warning');
		return false;
	}else if($("#notifytitle").val()==""){//如果主题为空，则提示是否需要填写主题，否则由系统自动设置
		$.messager.alert('提示','请填写主题！','warning');
		$("#notifytitle").focus();
		return false;
	}else if($('#notify_type').combo('getValue') == ''){
		$.messager.alert('提示','请选择发布类型！','warning');
		return false;
	}else{
		$('.notifyaddsub').linkbutton('disable');//发送数据前禁用发送按钮防止重复提交
		
		var attdaterand='',attnames='',attsize='';
		for(var i=0; i<fileList_notify.length; i++){
			attdaterand += fileList_notify[i].daterand+',';
			attnames += fileList_notify[i].name+'*';
			attsize += fileList_notify[i].size+',';//所有附件的和
		}
		
		$.post("<?php echo base_url()?>notify/notify_add",{
			p_notify_id:'<?php echo (!empty($arr[0]->notify_id))?$arr[0]->notify_id:'';?>',
			p_sj_id:$("#notify_add_sj_select_id").val(),
			p_sj_name:$("#notify_add_sj_select_user").val(),
			p_att_id:attdaterand,
			p_att_name:attnames,
			p_att_size:attsize,
			p_title:$("#notifytitle").val(),
			p_begin_date:$("#notyif_manage_ids").datebox('getValue'),
			p_end_date:$("#notyif_manage_ide").datebox('getValue'),
			p_content:getContent('notify_editor'),
			p_top:$("#notify_add_top_check").is(':checked'),//是否重要
			p_sms:$("#notify_add_alert_check").is(':checked'),//是否短信提醒
			p_type:$('#notify_type').combo('getValue')
		},
		function(data,status){
			if(data.success){
				$('#notify_in_list').datagrid('reload');//发送成功后刷新收件箱和发件箱
				$('#notify_sent_list').datagrid('reload');
				if(<?php echo @$status;?> == 1){
					$.messager.alert('提示','修改成功！','info');
					$('#main-tab').tabs('close', '新通告')
				}else{
					$.messager.confirm('提示', '通知公告发布成功，你要继续发布吗?', function(r){
						if (r){
							$("#notify_add_sj_select_id").val('');
							$("#notify_add_sj_select_user").val('');
							$("#notifytitle").val('');
							UE.getEditor('notify_editor').setContent('');
							$('.notifyaddsub').linkbutton('enable');//发送数据前禁用发送按钮防止重复提交
							
							var attdaterand='',attnames='',attsize='',fileList_notify=[],fileInfo = null;//清空附件相关变量
							$('#notify_file_upload').uploadify('cancel', '*');//关闭附件列表
							$("#notifytitle").focus();
							return false;
						}else{
							$('#main-tab').tabs('close', '新通告')
						}
					});	
				}
			}else{
				$.messager.alert('错误','发送失败！','error');
			}
		},'json');
	}

}



function notifyclose(){//如果邮件正在编辑，则弹出对话框询问
	if(getContent('notify_editor') != ''){
		$.messager.confirm('提示', '新通告正在编辑，确定退出吗?', function(r){
			if (r){
				$('#main-tab').tabs('close', '新通告');
			}
		});
	}else{
		$('#main-tab').tabs('close', '新通告');
	}
}
/*
function notifyinuser(v){//刷新两个区域，并定义标题和插入位置，弹出人员选择窗口，
	$('#selectuser_tree').tree('reload');
	$('#selectuser_list').datagrid('reload');
	var title;
	if(v === 'notify_add_sj'){
		title = '发布范围';
		destination_id = 'notify_add_sj';
	}
	$('#selectuser_dd').dialog({
		title: '选择'+title
	});
	$('#selectuser_dd').window('open');
}
*/
function nattopen(date,filename,oriname){//打开附件
	//alert(date+'/'+filename);
	//oriname = oriname.replace("(","（");
	//oriname = oriname.replace(")","）");
	oriname = encodeURIComponent(oriname);
	window.open("<?php echo base_url('notify/attopen');?>/"+date+'/'+filename+'/'+oriname);
}

function setnotify_att_obj(m,id,name,size){

	if(id.length > 0){
		//alert(size);
		//删除最后一个逗号
		id=id.substring(0,id.length-1);
		size=size.substring(0,size.length-1);
		name=name.substring(0,name.length-1);
		
		//把附件的ID和名称按分隔符分割为数组
		var ids= new Array(); //定义一数组 
			ids=id.split(","); //字符分割 
		var sizes= new Array(); //定义一数组 
			sizes=size.split(","); //字符分割 
		var names= new Array(); //定义一数组 
			names=name.split("*"); //字符分割 
		
		//循环赋值给fileList数组
		for (i=0;i<ids.length ;i++ ){ 
			var att_files = {};
				att_files = {
					'id':m+'_att_'+i,
					'daterand': ids[i],        //属性名用引号括起来，属性间由逗号隔开
					'name': names[i],
					'size': sizes[i]
				};			
			fileList_notify.push(att_files);
			//var attsize = size;//所有附件的和
			
			$("#"+m+"_file_upload-queue").append("<div id='"+m+"_att_"+i+"' class='uploadify-queue-item'><div class='cancel'><a href=\"javascript:$('#"+m+"_file_upload').uploadify('cancel', '"+m+"_att_"+i+"')\">X</a></div><span class='fileName'>"+subStringCh(names[i], 36, true)+"("+renderSize(sizes[i])+")</span><span class='data'></span><div class='uploadify-progress'><div class='uploadify-progress-bar' style='width: 100%;'><!--Progress Bar--></div></div></div>");
		}
		
		$("#"+m+"_file_upload-queue .cancel").on("click", function() {//JQUERY 2.0版本用on，1.9以前用live
			//取得本次取消的上传文件ID号		
			var fileId = $(this).parents(".uploadify-queue-item").attr("id");
			
			var fileInfo = null;
			//fileList_notify中保存了所有的已上传文件信息。
			for (var i=0; i<fileList_notify.length; i++) {
				if(fileList_notify[i].id == fileId) {
					fileInfo = fileList_notify[i];
					fileList_notify.splice(i, 1);
					break;
				}
			}
			
			//如果文件已经上传（即fileInfo不为空）
			if (fileInfo != null) {			
				$.post("<?php echo base_url().'attachment/upload_del'?>",{
					data:JSON.stringify(fileInfo),
					m:'notify'
				},function(data,status){
					if(!data.status){
						$.messager.alert('提示','文件未找到！','info');
						//alert('服务器端未能删除该文件');
					}
				},'JSON');
			}
		});
		//allPrpos ( fileList[0]);
	}	

}
<?php
if(!empty($arr[0]->attachment_id) && !empty($arr[0]->attachment_name) && !empty($arr[0]->size)){
?>
setnotify_att_obj('notify','<?php echo @$arr[0]->attachment_id;?>','<?php echo @$arr[0]->attachment_name;?>','<?php echo  @$arr[0]->size;?>');
<?php
}
?>
</script>
